<?
ini_set("display_errors",1);
include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

init_session();

$id = @intval($_GET['id']);

include($_SERVER['DOCUMENT_ROOT'].'/portals/header.inc.php');


$row = getRow("SELECT * FROM user WHERE user_id = $id");

if (empty($row)) {

	print "unknown user!";
	
} else {
	


	?>

	<h3>Portals profile page for <? echo he($row['realname']); ?></h3>

	<?

	print "<ul>";
	if ($row['geo_bi_id'])
		print " <li><a href=\"http://www.geograph.org.uk/profile/{$row['geo_bi_id']}\"><b>Geograph British and Ireland :: Profile</b> for ".he($row['realname'])."</a></li>";
	if ($row['geo_de_id'])
		print " <li><a href=\"http://geo-en.hlipp.de/profile/{$row['geo_bi_id']}\">Geograph Germany Profile</a></li>";
	print "</ul>";


	$sql = array();
	$sql['columns'] = '*';
	$sql['tables'] = array();
	$sql['tables'][] = "portal";
	$sql['wheres'] = array();

	$sql['wheres'][] = "status_id = 1";
	
	if (empty($_GET['_all']))
		$sql['wheres'][] = "public = 'Y'";
	$sql['wheres'][] = "user_id = $id";





	$query = sqlMakeQuery($sql);

	$data = getAssoc($query);



	if ($data) {
		print "<div class=important>Public portals by this user...";
		print "<ul class=\"list\">";
		foreach ($data as $id => $c) {

			print "<li>";
			print "<b><a href=\"http://".hec('domain').".portal.geographs.org/\" target=\"_blank\">".hec('title')."</a></b>";

			$count = count_active($id);
			print " [$count images]";

			if (!empty($_SESSION['user_id']) && $c['user_id'] == $_SESSION['user_id']) {
				print " <a href=\"portal.php?id=$id\" class=\"edit\">Edit</a>";
			}
			print "</li>";
		}
		print "</ul>";

		#print "<p><a href=\"edit.php\">Create your own</a>!</p>";
		print "</div>";
	} else {
		print "<p>This user has no public portals at this time.</p>";
		
		print "<p><a href=\"portals\">View all public portals</a></p>";
	}
}

include($_SERVER['DOCUMENT_ROOT'].'/portals/footer.inc.php');
